package controller

import (
	"im/dao"
	"im/model"
	"im/requests"
	"im/service"
)

type Groups struct {
	Base
}

func (g Groups) Get() {
	var pagination requests.Pagination
	rows, count, err := dao.NewGroupsAdmins().List(pagination)
	if err != nil {
		g.SendCry(err)
		return
	}
	resp := map[string]interface{}{
		"list":  rows,
		"count": count,
	}
	g.SendSmile(resp)
}
func (g Groups) Post() {
	var groupCreatable model.GroupsCreatable
	_ = g.Ctx.ReadJSON(&groupCreatable)
	var user = model.Users{}
	user.Id = 0
	user.AppsId = 1
	_, err := service.NewGroupService().Create(user, groupCreatable)
	if err != nil {
		g.SendCry(err)
		return
	}
	g.SendSmile(nil)
}
func (g Groups) PutBy(id int64) {
	var groupModifiable model.GroupsCreatable
	_ = g.Ctx.ReadJSON(&groupModifiable)
	err := service.NewGroupService().UpdateById(id, groupModifiable)
	if err != nil {
		g.SendCry(err)
		return
	}
	g.SendSmile(nil)
}
func (g Groups) DeleteBy(id int64) {
	var user = model.Users{}
	user.Id = 0
	user.AppsId = 1
	err := service.NewGroupService().DeleteByID(user.AppsId, id, user)
	if err != nil {
		g.SendCry(err)
		return
	}
	g.SendSmile(nil)
}